package com.ljc.service.impl;

import com.ljc.dao.AdminDao;
import com.ljc.model.Admin;
import com.ljc.service.AdminService;
import com.ljc.utils.BeanMapUtils;
import com.ljc.utils.MapParameter;
import com.github.pagehelper.PageHelper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

@Service("adminService")
public class AdminServiceImpl implements AdminService {
    @Autowired
    private AdminDao adminDao;
    @Override
    public int create(Admin admin){

        return adminDao.create(admin);

    }
    public int delete(Integer id){
        return adminDao.delete(MapParameter.getInstance().addId(id).getMap());
    }
    public int update(Admin admin){
        Map<String, Object> map = MapParameter.getInstance().put(BeanMapUtils.beanToMapForUpdate(admin)).addId(admin.getId()).getMap();
        return adminDao.update(map);
    }
    public List<Admin> query(Admin admin){
        PageHelper.startPage(admin.getPage(),admin.getLimit());
        Map<String, Object> map = MapParameter.getInstance().put(BeanMapUtils.beanToMap(admin)).getMap();
        return adminDao.query(map);
    }

    public Admin detail(Integer id){
        return adminDao.detail(MapParameter.getInstance().addId(id).getMap());
    }

    public int count(Admin admin){
        Map<String, Object> map = MapParameter.getInstance().put(BeanMapUtils.beanToMap(admin)).getMap();
        return adminDao.count(map);
    }

    /**
     * 管理员登录
     * @param userName
     * @param password
     * @return
     */
    public Admin login(String userName,String password){
        Map<String, Object> map = MapParameter.getInstance().add("userName",userName).add("password",password).getMap();
        return adminDao.detail(map);
    }
}
